//按钮注册事件案例，用于解决点击按钮，但是不知道谁点击了的问题
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class PanelButton : PanelBase
{
    public Button m_btn_1;
    public Button m_btn_2;
    public Button m_btn_3;
    public Button m_btn_4;
    
    protected override void Init()
    {
        base.Init();
        m_PanelType = EPanelType.Module;
        ClosePanel();

        if (m_btn_1 != null) m_btn_1.onClick.AddListener(delegate { OnClickEventSingleFirst(m_btn_1); });
        if (m_btn_2 != null) m_btn_2.onClick.AddListener(delegate { OnClickEventSingleSecond(m_btn_2); });
        if (m_btn_3 != null) m_btn_3.onClick.AddListener(delegate { OnClickEventButton(m_btn_3.name); });
        if (m_btn_4 != null) m_btn_4.onClick.AddListener(delegate { OnClickEventButton(m_btn_4.name); });
    }

    private void OnClickEventSingleFirst(Button btn)
    {
        Debug.Log($"注册按钮带自身数据的{btn.gameObject.name}");
    }
    
    private void OnClickEventSingleSecond(Button btn)
    {
        Debug.Log($"注册按钮带自身数据的{btn.gameObject.name}");
    }
    
    //通过名字判断执行事件的
    private void OnClickEventButton(string btnName)
    {
        switch (btnName)
        {
            case "btn_3":
                OnClickEventThird();
                break;
            case "btn_4":
                OnClickEventFourth();
                break;
            default:
                Debug.LogWarning("没有匹配到对应按钮的名称，请确认按钮名字正确！！！");
                break;
        }
    }
    
    private void OnClickEventThird()
    {
        Debug.Log($"按钮3执行了");
    }
    
    private void OnClickEventFourth()
    {
        Debug.Log($"按钮4执行了");
    }

}
